home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-21 | 2.6 KB | 57 lines | [TEXT/ToyS] |
- -- this library is SHAREWARE. If you keep it past the 10 day tryout period, you are
- -- REQUIRED to register it. If you decide not to keep it, please dispose of it.
-
- -- to register your copy, mail $5.00 U.S. to:
- -- Allan Crump
- -- P.O. Box 26322
- -- San Francisco, California 94111
- -- (in return I'll send you the latest registered copy of Date Conversions as well
- -- as some other useful methods of incorporating Julian dates into routines and programs
-
-
- property DateLib : "null" -- use this if you want to use the 'property'
-
- -- a fine place to put the library is in your System:Extensions:Scripting additions so that
- -- you can load them dynamically as follows (this code works on any machine)
-
- set pExt to (path to extensions as string) & "Scripting Additions:Date Conversions" as string
- if not class of DateLib = script then
- set DateLib to load script (alias pExt)
- end if
-
- --first, we'll tell datelib to convert the date "11/18/93 1:45:39 AM" to a full Julian number
- -- this is great for calculating the difference between two times in a day or
- -- two dates with mixed times. The decimal return of the number is the portion
- -- of the day in hundredths.
-
- tell DateLib to copy FullDateToJulian(date "Thursday, February 18, 1993 1:45:39 AM") to x
- display dialog (x as text)
-
-
- --then, we'll take that number and convert it back to the date format.
- --notice in some cases that there is a one-second variance in the return. This is due
- -- to the mathematics of the formula.
-
- tell DateLib to copy JulianToFullDate(x) to MyDate
- display dialog (MyDate as text)
-
- -- Now, let's say that we need to figure out the difference between just two dates.
- -- instruct Datelib to copy the DayToJulian of the date (like 11/17/93) to an integer Julian #
-
- tell DateLib to copy DayToJulian(date "Wednesday, November 17, 1993 12:00:00 AM") to x
- display dialog (x as text)
-
- -- Then we'll convert it back after doing mathematics on it and comparing it to a new number
- -- this is done with the JulianToDay statement as shown:
- tell DateLib to copy JulianToDay(x) to MyDate
- display dialog (MyDate as text)
-
- -- for example, you could take one date, say 09/14/88 and subtract
- -- another birthday like say, 08/02/86 and tell how many days were between them.
-
- tell DateLib to copy DayToJulian(date "Wednesday, September 14, 1988 12:00:00 AM") - DayToJulian(date "Saturday, August 2, 1986 12:00:00 AM") to diff
- display dialog (("There are " & diff as text) & " days between the two dates.")
-
- -- Have Fun ! Remember, if you want to use this function in a routine, you'll be bothered
- -- with the nasty "Register" message occasionally, until it's registered.
- -- Allan